package gov.pbc.gx.nn.pz.bdf.interceptor;

import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang.StringUtils;

import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.dorado.common.proxy.PatternMethodInterceptor;
import com.bstek.dorado.core.Configure;
import com.bstek.dorado.view.resolver.ClientRunnableException;

public class TimeoutInvokeInterceptor extends PatternMethodInterceptor {

	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		if (StringUtils.isBlank(ContextHolder.getLoginUserName())) {
			String loginUrl = Configure.getString("bdf2.formLoginUrl");
			StringBuffer sb = new StringBuffer();
			sb.append("var d = dorado.MessageBox.getDialog();");
			sb.append("d.set('closeable', false);");
			sb.append("dorado.MessageBox.show({icon : 'WARNING',buttons:['ok'],message :'由于您长时间未操作，因此您需要重新登录！',callback:function(){window.top.location.href='"
					+ loginUrl + "';}})");
			throw new ClientRunnableException(sb.toString());
		} else {
			return invocation.proceed();
		}
	}

}
